﻿using System;

namespace design_patterns_book
{
    class Program
    {
        static void Main(string[] args)
        {

            #region 一
            //Console.Write("请输入数字A:");
            //string A = Console.ReadLine();
            //Console.Write("请选择运算符号（+、-、*、/）");
            //string B = Console.ReadLine();
            //Console.Write("请输入数字B:");
            //string C = Console.ReadLine();
            //string D = "";

            //if (B == "+")
            //{
            //    D = Convert.ToString(Convert.ToDouble(A) + Convert.ToDouble(C));
            //}

            //if (B == "-")
            //{
            //    D = Convert.ToString(Convert.ToDouble(A) - Convert.ToDouble(C));
            //}

            //if (B == "*")
            //{
            //    D = Convert.ToString(Convert.ToDouble(A) * Convert.ToDouble(C));
            //}

            //if (B == "/")
            //{
            //    D = Convert.ToString(Convert.ToDouble(A) / Convert.ToDouble(C));
            //}

            //Console.WriteLine("结果是：" + D);

            #endregion


            #region two
            try
            {
                Console.Write("请输入数字A:");
                string strNumberA = Console.ReadLine();
                Console.Write("请选择运算符号（+、-、*、/）");
                string strOperate = Console.ReadLine();
                Console.Write("请输入数字B:");
                string strNumberB = Console.ReadLine();
                string strResult = "";

                switch (strOperate)
                {
                    case "+":
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) + Convert.ToDouble(strNumberB));
                        break;
                    case "-":
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) - Convert.ToDouble(strNumberB));
                        break;
                    case "*":
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) * Convert.ToDouble(strNumberB));
                        break;
                    case "/":
                        if (strNumberB != "0")
                        {
                            strResult = Convert.ToString(Convert.ToDouble(strNumberA) / Convert.ToDouble(strNumberB));
                        }
                        else
                        {
                            strResult = "除数不能为0";
                        }
                        break;

                }

                Console.WriteLine("结果是：" + strResult);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("your write is error");
            }
            #endregion

            #region three
            try
            {
                Console.Write("请输入数字A:");
                string strNumberA = Console.ReadLine();
                Console.Write("请选择运算符号（+、-、*、/）");
                string strOperate = Console.ReadLine();
                Console.Write("请输入数字B:");
                string strNumberB = Console.ReadLine();
                string strResult = "";

                strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNumberB),
                    strOperate));[[2]]

                Console.WriteLine("结果是：" + strResult);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("your write is error");
            }
            #endregion

            Operation oper;
            oper = OperationFactory.createOperate("+");
            oper.NumberA = 1;
            oper.NumberB = 2;
            double result = oper.GetResult();
        }
    }

    public class Operation
    {
        //public static double GetResult(double numberA, double numberB, string opearte)
        //{
        //    double result = 0d;
        //    switch (opearte)
        //    {
        //        case "+":
        //            result = numberA + numberB;
        //            break;
        //        case "-":
        //            result = numberA - numberB;
        //            break;
        //        case "*":
        //            result = numberA * numberB;
        //            break;
        //        case "/":
        //            if (numberB != 0)
        //            {
        //                result = numberA / numberB;
        //            }
        //            break;

        //    }


        //    return result;
        //}

        private double _numberA = 0;
        private double _numberB = 0;

        public double NumberA
        {
            get
            {
                return _numberA;
            }

            set
            {
                _numberA = value;
            }
        }

        public double NumberB
        {
            get { return _numberB; }
            set { _numberB = value; }
        }

        public virtual double GetResult()
        {
            double result = 0;
            return result;
        }
    }

    class OperationAdd : Operation
    {
        public override double GetResult()
        {
            double result = 0;
            result = NumberA - NumberB;
            return result;
        }
    }


    public class OperationFactory
    {
        public static Operation createOperate(string operate)
        {
            Operation oper = null;
            switch (operate)
            {
                case "+":
                    oper = new OperationAdd();
                    break;
                default:
                    break;
            }

            return oper;
        }
    }

    interface IFly
    {
        void Fly();
    }

    interface ILanguage
    {
        void Speak();
    }

    class Bird
    {

    }
}

